package ${setServicePackageName};

import java.util.Arrays;
import ${setDomainPackageName}.${DOMAIN_CLASSNAME};
import ${setMapperPackageName}.${MAPPER_CLASSNAME};
import com.fangx.app.basic.utils.CheckObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ${pagingQueryDto};
import ${pagingResultDto};
import java.util.List;
import com.google.common.collect.Lists;


/**
 * Description:${tableAnnotation}服务类
 * @author ${author}
 * @date ${date}
 */
@Service
@Transactional
public class ${SERVICE_CLASSNAME} {

    private final ${MAPPER_CLASSNAME} ${mapper_classname};

    @Autowired
    public ${SERVICE_CLASSNAME}(${MAPPER_CLASSNAME} ${mapper_classname}) {
        this.${mapper_classname} = ${mapper_classname};
    }

    /** 
     * Description:新增${tableAnnotation}
     *
     * @param ${domain_classname} ${tableAnnotation}
     * @return int
     * @author ${author}
     * @date ${dateTime}
     */
    public int create(${DOMAIN_CLASSNAME} ${domain_classname}){
        return this.${mapper_classname}.create(${domain_classname});
    }

    /** 
     * Description:根据id修改${tableAnnotation}
     *
     * @param ${domain_classname} ${tableAnnotation}
     * @return int
     * @author ${author}
     * @date ${dateTime}
     */
    public int updateById(${DOMAIN_CLASSNAME} ${domain_classname}){
        return this.${mapper_classname}.updateById(${domain_classname});
    }

    /** 
     * Description:根据ids删除${tableAnnotation}
     *
     * @param ids id字符串数组
     * @return int
     * @author ${author}
     * @date ${dateTime}
     */
    public int deleteByIds(String ids){
        return this.${mapper_classname}.deleteByIds(Arrays.asList(ids.split(",")));
    }
    
    /** 
     * Description:根据id查找${tableAnnotation}
     *
     * @param id id
     * @return ${setDomainPackageName}.${DOMAIN_CLASSNAME}
     * @author ${author}
     * @date ${dateTime}
     */
    public ${DOMAIN_CLASSNAME} selectById(${primaryKeyModtype} id){
        return this.${mapper_classname}.selectById(id);
    }

    <#--/**
     * Description: 查询${tableAnnotation}总记录数
     *
     * @param pagingQueryDto
     * @return long
     * @author ${author}
     * @date ${dateTime}
     */
    public long count(PagingQueryDto<${DOMAIN_CLASSNAME}> pagingQueryDto){
        return this.${mapper_classname}.select${DOMAIN_CLASSNAME}Counts(pagingQueryDto);
    }
    -->
    /** 
     * Description: 查询${tableAnnotation}分页列表
     *
     * @param pagingQueryDto 分页请求对象
     * @return ${pagingResultDto}<${setDomainPackageName}.${DOMAIN_CLASSNAME}>
     * @author ${author}
     * @date ${dateTime}
     */
    public PagingResultDto<${DOMAIN_CLASSNAME}> pageList(PagingQueryDto<${DOMAIN_CLASSNAME}> pagingQueryDto) {
       long total = 0;
       List<${DOMAIN_CLASSNAME}> resultList = Lists.newArrayList();
       if (CheckObjectUtils.nonNull(pagingQueryDto.getRows())) {
           total = this.${mapper_classname}.select${DOMAIN_CLASSNAME}Counts(pagingQueryDto);
           if(total > 0){
               resultList = this.${mapper_classname}.select${DOMAIN_CLASSNAME}List(pagingQueryDto);
           }
       }
       return PagingResultDto.of(pagingQueryDto, total, resultList);
    }


}

